<?
require_once("IEndpointRetriever.php");
require_once("HttpEndpointRetriever.php");
class ObjectEndpointRetriever implements IEndpointRetriever
{
	protected $httpEndpointRetriever;
	protected $decodeCallback;

	public function ObjectEndpointRetriever(HttpEndpointRetriever $httpEndpointRetriever, callback $decodeCallback = null)
	{
		$this->decodeCallback = ($decodeCallback == null ? "json_decode" : $decodeCallback);
		/*if (!is_callable($decodeCallback))
		{
			throw new Exception("decodeCallback must be a callback");
		}*/
		$this->httpEndpointRetriever = $httpEndpointRetriever;
	}

	public function RetrieveEndpoint(Endpoint $endpoint)
	{
		return call_user_func($this->decodeCallback, 
			$this->httpEndpointRetriever->RetrieveEndpoint($endpoint));
		//return json_decode($this->httpEndpointRetriever->RetrieveEndpoint($endpoint));
	}
}
?>
